import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import css from './condition.module.scss'
import { dateFormat } from '@/utils'
export default class LotteryCondition extends PureComponent {
    static propTypes = {
        prizes: PropTypes.object
    }

    get hasPrizes() {
        return !!this.props.prizes
    }

    get openTime() {
        return this.props?.prizes?.lottery_time ?? ''
    }

    get condition() {
        let data = ''
        if (this.hasPrizes) {
            const prize = this.props.prizes
            data += (prize.lottery_feed_limit === 1 ? '关注我、' : '')
            data += (prize.business_type === 9 ? '在本评论区发布评论' : '转发本动态')
            data += (prize.lottery_at_num > 0 ? `并@${prize.lottery_at_num}位好友` : '')
        }
        return data
    }

    get scope() {
        let data = ''
        if (this.hasPrizes) {
            const prize = this.props.prizes
            data += (prize.lottery_feed_limit === 1 ? '仅粉丝' : '所有用户')
        }
        return data
    }

    get winnerCount() {
        let data = 0
        if (this.hasPrizes) {
            const prize = this.props.prizes
            data = prize.first_prize + prize.second_prize + prize.third_prize
        }
        return data
    }

    render() {
        return (
            <ul className={css["wrap"]}>                
                { this.openTime && <li>开奖时间：{dateFormat(new Date(this.openTime*1000), 'yyyy年MM月dd日 hh:mm')}</li> }                
                { this.condition && <li>互动条件：{this.condition}</li> }                
                { this.scope && <li>抽奖范围：{this.scope}</li> }
                { this.winnerCount && <li>抽取人数：{this.winnerCount}名</li> }
            </ul>                
        )
    }
}
